<?php

namespace App\Package\Finance;

use App\Package\Finance\Contracts\OperandContract;
use Illuminate\Support\Facades\DB;

/**
 * 表达式操作数
 *
 * Date: 2018/6/6
 * @author George
 * @package App\Package\Finance
 */
class Operand implements OperandContract
{
	/**
	 * 定义属性
	 *
	 * @var array
	 * Date: 2018/6/6
	 * @author George
	 */
	protected $attributes = [];

	/**
	 * 获取值
	 *
	 * Date: 2018/6/6
	 * @author George
	 * @param $key
	 * @return mixed|null
	 */
	public function get($key)
	{
		if (! $key) {
			return null;
		}
		return array_get($this->attributes, $key);
	}

	/**
	 * 设置属性
	 *
	 * Date: 2018/6/6
	 * @author George
	 * @param $key
	 * @param $value
	 * @return $this|mixed
	 */
	public function set($key, $value)
	{
		if ($key && $value) {
			$this->attributes[$key] = $value;
		}
		return $this;
	}

	public function field()
	{

	}

	public function query(string $table, array $field, array $condition)
	{
		$query = DB::table($table)->select($field)->where($condition);
	}

	/**
	 * 获取属性魔术方法
	 *
	 * Date: 2018/6/6
	 * @author George
	 * @param $key
	 * @return mixed
	 */
	public function __get($key)
	{
		return $this->get($key);
	}

	/**
	 * 设置属性魔术方法
	 *
	 * Date: 2018/6/6
	 * @author George
	 * @param $key
	 * @param $value
	 */
	public function __set($key, $value)
	{
		$this->set($key, $value);
	}
}
